Perl glob()函数

您所在的位置:网站首页 perl 获取参数 Perl glob()函数

Perl glob()函数

2023-09-04 19:22| 来源: 网络整理| 查看: 265

Perl glob()函数

Perl中的glob()函数是用来打印作为参数传递给它的目录中的文件的。这个函数可以打印所有的或特定的文件,这些文件的扩展名已被传递给它。

语法: glob(Directory_name/File_type)。

参数: 要打印的文件所在目录的路径。

返回: 在给定目录中存在的文件的列表

例1: 打印目录中所有文件的名称

#!/usr/bin/perl    # To store the files # from the directory in the array @files = glob('C:/Users/GeeksForGeeks/Folder/*');    # Printing the created array print "@files\n";

输出:

Perl glob()函数 上面的例子将打印请求目录下的所有文件。

例2: 打印目录中特定文件的名称

#!/usr/bin/perl    # To store the files of a specific extension # from the directory in the array @Array = glob('C:/Users/GeeksForGeeks/Folder/*.txt');    # Printing the created array print "@Array\n";

输出:

Perl glob()函数 上面的例子将打印所请求的目录中以.txt结尾的所有文件。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3